package 多线程.懒汉模式;

class Singleton {
    private static volatile Singleton Instance = null;//volatile 防止指令重排序 和 内存可见性（jvm优化了）
    static Object locker = new Object();//枷锁
    public static Singleton getInstance(){
        if(Instance == null){//防止多次枷锁
            synchronized(locker){
                if(Instance == null){
                    Instance = new Singleton();
                }
            }
        }
        return Instance;
    }
}
public class SingletonLazy2 {
    public static void main(String[] args) {

    }
}
